<?php 
namespace App\Http\Controllers\Home;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Home\ThrottlesLogins;
use Illuminate\Foundation\Home\AuthenticatesAndRegistersUsers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use Session;
header('content-type:text/html;charset=utf8');

class BrandController extends Controller{
	public $model=false;

	public function __construct(){

	      $this->model = new \App\Brand_Home();
	}
	public function brand(){

		$brand_list=$this->model->lists();
		$category = session::get('category');

		return view('Home/brand',['brand_list'=>$brand_list,'ak'=>$category]);
	}
	
	public function brandlist($brand_id){
		//查询当前品牌下的所有商品
		$goodsList=$this->model->goodsList($brand_id);
		
		//单条品牌信息
		$brandOne=$this->model->getOne($brand_id);
		
		return view('Home/brandlist',['goodsList'=>$goodsList,'brandOne'=>$brandOne,'class'=>'now']);
	}

	public function brand_hot($brand_id){
		//查询当前品牌下的所有热销商品
		$goodsList=$this->model->hot($brand_id);
		//单条品牌信息
		$brandOne=$this->model->getOne($brand_id);
		
		return view('Home/brandlist',['goodsList'=>$goodsList,'brandOne'=>$brandOne,'class'=>'hotnow']);
	}

		public function brand_new($brand_id){
		//查询当前品牌下的所有新品商品
		$goodsList=$this->model->brand_new($brand_id);
		//单条品牌信息
		$brandOne=$this->model->getOne($brand_id);
		
		return view('Home/brandlist',['goodsList'=>$goodsList,'brandOne'=>$brandOne,'class'=>'newnow']);
	}
	//品牌列表商品添加收藏夹
	public function addcollect($goods_id){
		if(Session::has('user_id') && Session::has('user_name')){
			$user_id = session::get('user_id');
			//判断当前用户 和 当前商品在不在收藏夹内
			$list=$this->model->checkGoods($goods_id,$user_id);
			$list=array_map('get_object_vars', $list);
			if(!empty($list[0])){
				echo '<script>alert("您已收藏过该商品");history.go(-1)</script>';die;
			}
			$res=$this->model->addgoods($goods_id,$user_id);
			if($res){
				echo '<script>alert("添加收藏夹成功");history.go(-1)</script>';
			}
		}else{
			echo '<script>alert("您还没登录,请先登录！！！");window.location.href="/home/login"</script>';
		}
	}

	
}